﻿using Header.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Security.Permissions;

namespace Header.Security
{
	class ChauLucPrincipalV1 : IPrincipal
	{
		/// <summary>
		/// use to read roles of a user from the database
		/// </summary>
		private IRoleReader rolereader;

		/// <summary>
		/// 
		/// </summary>
		private IIdentity identity;

		/// <summary>
		/// Create new ChauLucPrincipalV1 object 
		/// </summary>
		/// <param name="rolereader"></param>
		public ChauLucPrincipalV1(IRoleReader rolereader)
		{
			this.rolereader = rolereader;
		}
		IIdentity IPrincipal.Identity
		{
			get { return Thread.CurrentPrincipal.Identity; }
		}

		bool IPrincipal.IsInRole(string role)
		{
			var roles = rolereader.GetRole(this.identity.Name);
			var isin = roles.Contains(role);
			return isin;
		}
	}
}
